import pymongo

class louisMongo():

    def __init__(self, init=True):
        # Another connection form
        # Client = pymongo.MongoClient("mongodb://louisyoung.work:27017/")
        self.init = init
        host = "louisyoung.work"
        port = 27017
        self.Client = pymongo.MongoClient(host=host, port= port)

        if self.init:
            # Show Databases List
            print("DBList -- >")
            self.DBList = self.Client.list_database_names()
            print(self.DBList)
            print("NEXT -- > self.DB( <DB-Name> )")

    def DB(self, DBName):

        self.DB = self.Client[DBName]

        if self.init:
            self.DBName = DBName
            # Show Collection List
            print("ColList -- >")
            self.ColList = self.DB.list_collection_names()
            print(self.ColList)
            print("NEXT -- > self.Col( <Col-Name> )")

    def Col(self, ColName):

        self.Col = self.DB[ColName]

        if self.init:
            self.ColName = ColName
            for Doc in self.Col.find():
                print(Doc)
            print("NEXT -- > Col = self.Get()")

    def Get(self):

        if self.init:
            print("mongo = louisMongo(init=False)")
            print("mongo.DB('{}')".format(self.DBName))
            print("mongo.Col('{}')".format(self.ColName))
            print("mongo = mongo.Get()".format(self.ColName))

        return self.Col
